package com.example.wkable.exoplayer.extensions

import android.app.Activity
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.support.annotation.IntRange
import android.support.v4.app.ActivityCompat
import android.widget.Toast

fun Activity.checkPermission(requester: Activity, permission: String, requestCode: Int): Boolean {
    if (Build.VERSION.SDK_INT < 23) {
        return true
    }
    if (ActivityCompat.checkSelfPermission(
            this,
            android.Manifest.permission.WRITE_EXTERNAL_STORAGE
        ) != PackageManager.PERMISSION_GRANTED
    ) {
        requester.requestPermissions(arrayOf(permission), requestCode)
        return false
    }
    return true
}

fun Any.toast(
    context: Context, msg: String, @IntRange(
        from = Toast.LENGTH_SHORT.toLong(),
        to = Toast.LENGTH_LONG.toLong()
    ) length: Int
) {
    Toast.makeText(context, msg, length).show()
}